<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的优惠券</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>
</head>
<body class="bg-eee">
    <header class="header">
        <div class="backPrevPage on" onclick="historyBack()"></div>
        <div class="pageTitle">我的优惠券</div>

    </header>
    <section class="couponPage HTML_BOX">

       <ul class="couponList plr">
        <!-- on表示可用。 没有on表示不可用或已使用 -->
        <!-- coupon_go去使用 coupon_icon1已使用 coupon_icon2已过期 -->
           <!-- <li class="on">
               <div class="couponLeft">
                   <div class="">$<span class="coupon_price">50</span></div>
                   <div class="coupon_cond">满500使用</div>
               </div>
               <div class="couponRight">
                   <div class="couponInfo">
                       <div class="couponTitle">仅限水果类商品可用</div>
                       <div class="couponTime">2018-12-8~12-12</div>

                   </div>
                   <div class="coupon_go">去使用</div>
               </div>
           </li>
           <li class="on">
               <div class="couponLeft">
                   <div class="">$<span class="coupon_price">50</span></div>
                   <div class="coupon_cond">满500使用</div>
               </div>
               <div class="couponRight">
                   <div class="couponInfo">
                       <div class="couponTitle">仅限水果类商品可用</div>
                       <div class="couponTime">2018-12-8~12-12</div>
                   </div>
                   <div class="coupon_go">去使用</div>
               </div>
           </li>
           <li class="">
               <div class="couponLeft">
                   <div class="">$<span class="coupon_price">50</span></div>
                   <div class="coupon_cond">满500使用</div>
               </div>
               <div class="couponRight">
                   <div class="couponInfo">
                       <div class="couponTitle">仅限水果类商品可用</div>
                       <div class="couponTime">2018-12-8~12-12</div>
                   </div>
                   <div class="coupon_icon1"></div>
               </div>
           </li>
           <li class="">
               <div class="couponLeft">
                   <div class="">$<span class="coupon_price">50</span></div>
                   <div class="coupon_cond">满500使用</div>
               </div>
               <div class="couponRight">
                   <div class="couponInfo">
                       <div class="couponTitle">仅限水果类商品可用</div>
                       <div class="couponTime">2018-12-8~12-12</div>
                   </div>
                   <div class="coupon_icon2"></div>
               </div>
           </li> -->
       </ul>
       
       <div class="pageHide dn">暂无数据..</div>
    </section>
    <!-- 弹窗 -->
  <div class="mask_pop">
    <div class="mask" ></div>
    <div class="coupon_pop">
        <div class="coupon_popImage">
            <img src="../image/coupon_pop_bg.png"/>

        </div>
        <div style="margin-top: .5rem">恭喜你！兑换成功</div>
        <div style="margin-top: .2rem">可以在我的优惠券里查看</div>
        <div class="coupon_pop_btn f_c">立刻查看</div>
        <div id="coupon_close" class="pop_close"></div>
    </div>
  </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var page = 1;
    var ifpage = true;
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                 threshold: 10
            }
         }, function(ret, err) {
             //页码+1，继续请求数据
             
             if(ifpage){
                page++;
                ready();
             }
             
        });
        ifCnAndEn();
        ready();
    };

    function ready(){
      getAjax(Interface.member_coupon,{token:token,type:0,page:page},function(res){
        console.log(JSON.stringify(res));
        var list = res.data;
        if(page==1){
            $(".wareList_1").empty();
        }
        if(list!="" && list !=null && list !=false){
            $(".pageHide").addClass("dn");ifpage=true;
            $.each(list,function(i,item){
                var html ='<li class="on">';
                     html+='<div class="couponLeft">';
                           html+='<div class="">$<span class="coupon_price">'+item.val3+'</span></div>';
                           html+='<div class="coupon_cond">满'+item.manzu+'使用</div>';
                       html+='</div>';
                       html+='<div class="couponRight">';
                           html+='<div class="couponInfo">';
                               html+='<div class="couponTitle">'+item.title+'</div>';
                               html+='<div class="couponTime">'+timestampToTime(item.start_time)+'~'+timestampToTime(item.end_time)+'</div>';
                           html+='</div>';
                           shiyong = '去使用';
                           coupon_icon1 = 'coupon_icon1';
                           coupon_icon2 = 'coupon_icon2';
                           if(cnen==2){
                              shiyong ='Go to use';
                              coupon_icon1 = 'coupon_icon1_en';
                              coupon_icon2 = 'coupon_icon2_en';
                           }
                           var timestamp = Date.parse(new Date());
                            console.log(timestamp /1000);
                            console.log(item.end_time);
                           if(item.is_use==0){
                              if(item.end_time < timestamp /1000){
                                 html+='<div class="'+coupon_icon2+'"></div>';
                              }else{
                                html+='<div onclick="openWin(\'index\',\'index.html\')" class="coupon_go">'+shiyong+'</div>';
                              }
                           }else if(item.is_use==1){
                              html+='<div class="'+coupon_icon1+'"></div>';
                           }else{
                              html+='<div class="'+coupon_icon2+'"></div>';
                           }
                       html+='</div>';
                   html+='</li>';
                  $(".couponList").append(html);
            })
            if(list.length<10){
                $(".getPage").hide();
            }
        }else{
            $(".getPage").hide();
        }
      },function(res,err){
        
      })
    }

    function timestampToTime(timestamp) {
    //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var date = new Date(timestamp * 1000);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
        return Y+M+D;
    }

</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".pageTitle").eq(0).html('My Coupons');
            
        }
    }
</script>
</html>
